package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysSubject;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ISysSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 主题
 *
 * @author hwh
 */
@Api(value = "/system/subject", tags = {"主题"})
@RestController
@RequestMapping("/system/subject")
public class SysSubjectController extends BaseController {

    @Resource
    private ISysSubjectService sysSubjectService;

    /**
     * 新增主题
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "SysSubject", name = "sysSubject", value = "", required = true)
    })
    @ApiOperation(value = "新增主题", notes = "新增主题", httpMethod = "POST")
    @PostMapping("/add")
    @Log(title = "主题管理", businessType = BusinessType.INSERT)
    public AjaxResult add(@Validated @RequestBody SysSubject sysSubject) {
        return toAjax(sysSubjectService.addSubject(sysSubject));
    }


    /**
     * 获取主题列表
     */
    @ApiOperation(value = "获取主题列表", notes = "获取主题列表", httpMethod = "GET")
    @GetMapping("/list")
    public AjaxResult list(SysSubject sysSubject) {
        return success(sysSubjectService.selectSubjectList(sysSubject));
    }

    /**
     * 删除主题
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "subjectId", value = "", required = true)
    })
    @ApiOperation(value = "删除主题", notes = "删除主题", httpMethod = "DELETE")
    @Log(title = "主题管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{subjectId}")
    public AjaxResult remove(@PathVariable("subjectId") Integer subjectId) {
        return toAjax(sysSubjectService.deleteSubject(subjectId));
    }
}
